#include<string>
#include<vector>
#include<iostream>

size_t split(std::string str,std::string sep,std::vector<std::string>&result)
{
    //字符串分割思想:从0下标的位置开始查找指定字符，进行切割
    //再重找到的指定字符下标的位置，继续往后找
    //news.music.pop.#
    size_t pos,idx=0;
    while(idx<str.size())
    {
        pos=str.find(sep,idx);
        if(pos==std::string::npos)
        {      
            result.push_back(str.substr(idx));//已经找不到sep所以要把最后的字符串加上
            return result.size();
        }
        //pos=idx说明有连续的分割符
        if(pos==idx)
        {
            idx=pos+sep.size();
            continue;
        }
        result.push_back(str.substr(idx,pos-idx));
        idx=pos+sep.size();
    }
    return result.size();
}

int main()
{
    std::vector<std::string> v;
    std::string str="news....music.pop.#";
    size_t n=split(str,".",v);
    for(auto&e:v)
    {
        std::cout<<e<<std::endl;
    }
    return 0;
}